<?php
function GetCount ($numcount, $base_num)
{
    $c = 0;
    switch ($base_num)
    {
        case 4 :
            $c = $numcount * ( $numcount - 1 ) * ( $numcount - 2 ) * ( $numcount - 3 ) / 24;
            break;
		case 3 :
            $c = $numcount * ( $numcount - 1 ) * ( $numcount - 2 ) / 6;
            break;
        case 2 :
            $c = $numcount * ( $numcount - 1 ) / 2;
            break;
    }
    return $c;
}

function betin ($bettype, $num, $rate1, $rate, $money, $betcounts, $prot_start, $stime, $amount2, $idisk)
{
    global $curruser;
    global $lotto_id;
    $useAmt = Get_bet_amounts_Info($bettype, implode(",", $num), 0);
    if ($amount2 < $money + $useAmt)
    {
        return false;
    }
    $numbers = $money . "|" . $rate . "|" . $betcounts . "|" . implode(",", $num);
    $fields = array();
    $fields['user_id'] = $curruser['id'];
    $fields['lotto_id'] = $lotto_id;
    $fields['createtime'] = $stime;
    $fields['bettype'] = $bettype;
    $fields['numbers'] = "'{$numbers}'";
    $fields['amount'] = $money * $betcounts;
    $fields['line_nums'] = "'" . implode(",", $num) . "'";
    $fields['unitmoney'] = $money;
    $fields['rate'] = $rate1;
    $fields['payoff'] = round($money * ( $rate1 - 1 ));
    $fields['disk'] = $idisk;
    $u2 = get_user($curruser['prev_id']);
    $u3 = get_user($u2['prev_id']);
    $u4 = get_user($u3['prev_id']);
    $u5 = get_user($u4['prev_id']);
    $fields['acl2'] = $u2['id'];
    $fields['acl3'] = $u3['id'];
    $fields['acl4'] = $u4['id'];
    $fields['acl5'] = $u5['id'];
    $a1 = GetBack($curruser['id'], $fields['bettype'], $idisk, 1);
    $a2 = GetBack($u2['id'], $fields['bettype'], $idisk, 2);
    $a3 = GetBack($u3['id'], $fields['bettype'], $idisk, 3);
    $a4 = GetBack($u4['id'], $fields['bettype'], $idisk, 4);
    $a5 = GetBack($u5['id'], $fields['bettype'], $idisk, 5);
    $fields['back1'] = $a1;
    $fields['back2'] = $a2;
    $fields['back3'] = $a3;
    $fields['back4'] = $a4;
    $fields['back5'] = $a5;
    $a6 = GetBack($u5['supe_account'], $fields['bettype'], $idisk, 255);
    $fields['back6'] = $a6;
    $protmod = $u5['protmod'];
    $fields['mpercent'] = $u2['mpercent'];
    $fields['percent2'] = $u2['percent0'];
    $fields['percent3'] = min($u3['percent1'], $u4['mpercent'] - $fields['mpercent'] - $fields['percent2']);
    $fields['percent4'] = min($u4['percent1'], $u5['mpercent'] - $fields['mpercent'] - $fields['percent2'] - $fields['percent3']);
    $fields['upercent'] = 100 - $fields['mpercent'] - $fields['percent2'] - $fields['percent3'] - $fields['percent4'];
    if ($fields['upercent'] < 0 || $fields['percent3'] < 0 || $fields['percent4'] < 0)
    {
        account_err("系统参数严重错误！");
    }
    $fields['r2'] = $money * $fields['percent2'] / 100;
    $fields['r3'] = $money * $fields['percent3'] / 100;
    $fields['r4'] = $money * $fields['percent4'] / 100;
    $fields['r6'] = $money * $fields['upercent'] / 100;
    $fields['ip'] = "'" . getIP() . "'";
    $newid = db_insert("bet", $fields);
    if (!$newid)
    {
        return false;
    }
	$rs=getdb("select user_id from k_user_bet where user_id='".$curruser['id']."' and lotto_id='$lotto_id'");
	if(!$rs->eof)
		getdb("update k_user_bet set amount_6h=amount_6h+".$money." where user_id='".$curruser['id']."' and lotto_id='$lotto_id'");
	else
		getdb("insert into k_user_bet set amount_6h=amount_6h+".$money." ,user_id='".$curruser['id']."',lotto_id='$lotto_id'");
    if ($prot_start == 1 && $protmod == 1)
    {
        $tmpnum = implode(",", $num);
        auto_prots(2, $bettype, $tmpnum, $rate, $u2, $u3, $u4, $u5, $stime, $betcounts);
        auto_prots(3, $bettype, $tmpnum, $rate, $u2, $u3, $u4, $u5, $stime, $betcounts);
        auto_prots(4, $bettype, $tmpnum, $rate, $u2, $u3, $u4, $u5, $stime, $betcounts);
        auto_prots(5, $bettype, $tmpnum, $rate, $u2, $u3, $u4, $u5, $stime, $betcounts);
    }
    return true;
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if (!isset($_POST['type']))
{
    account_err("错误的参数！");
}
$bettype = intval($_POST['type']);
$bettypeArr = array(7, 8, 9, 10, 11, 48);
if (!in_array($bettype, $bettypeArr))
{
    account_err("错误的参数(type)！");
}
if (!isset($_POST['num1']))
{
    account_err("错误的参数(num1)！");
}
$num1 = $_POST['num1'];
if ($num1 == "")
{
    account_err("请选择号码！");
}
$num_r1 = explode(",", $num1);
$normal = !isset($_POST['num2']);
$num2 = "";
$num_r2 = array();
if (!$normal)
{
    $num2 = $_POST['num2'];
    if ($num1 == "")
    {
        account_err("错误的参数(num2)！");
    }
    $num_r2 = explode(",", $num2);
}
$betUnionNum = intval($_POST['betUnionNum']);
if ($betUnionNum < 1)
{
    account_err("错误的参数(betUnionNum)！");
}
$ui = new UI();
$conf = new Config();
$linecount = intval($conf->get("line_max_count"));
switch ($bettype)
{
    case 8 :
    case 9 :
    case 33 :
        $count_num = 3;
        break;
	case 48 :
        $count_num = 4;
        break;
    default :
        $count_num = 2;
        break;
}
if ($normal)
{
    if (count($num_r1) < $count_num)
    {
        account_err("至少选择 {$count_num} 个号码！");
    }
    else if ($linecount < count($num_r1))
    {
        account_err("最多只能选择 " . $linecount . " 个号码！");
    }
}
$tpl = new Template2();
$tpl->load(array("main" => "proc12.htm"));
$tpl->set("account", $curruser['account']);
if ($curruser['enabled'] == 0 || $curruser['enabled'] == 2)
{
    $ui->showErrorPage("<p class=error>帐号已被暂停使用</p>");
    exit();
}
$rs = getdb("select * from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>目前没有可以下注期数！</p>");
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$lotto_ns = $rs->f['n1'] + $rs->f['n2'] + $rs->f['n3'] + $rs->f['n4'] + $rs->f['n5'] + $rs->f['n6'];
$prot_start = $conf->get("protect_start");
$stopbet = $conf->get("linebet");
if (date("Y-m-d") < $open)
{
    exit();
}
else if (date("Y-m-d") == $open)
{
    if ($stopbet <= date("Hi") || 0 < $lotto_ns)
    {
        $ui->showErrorPage("<p>下注期数：" . d3($round) . "<br>开奖日：" . $open . "</p>" . "<p class=error>已经截止下注！</p>");
        exit();
    }
    else if (date("Hi") <= $conf->get("startbet"))
    {
        exit();
    }
}
$tpl->set("open", $open);
$tpl->set("round", d3($round));
$tpl->set("lotto_id", $lotto_id);
$tpl->set("account", $curruser['account']);
$tpl->set("amount", $curruser['amount']);
$chktime2 = 0;
if ($bettype == 9 || $bettype == 33)
{
    $chk_rs = getdb("select MAX(createtime) from bet where lotto_id=" . $lotto_id . " and user_id=" . $curruser['id'] . " and bettype in (9,33) and rame=0");
}
else if ($bettype == 10 || $bettype == 32)
{
    $chk_rs = getdb("select MAX(createtime) from bet where lotto_id=" . $lotto_id . " and user_id=" . $curruser['id'] . " and bettype in (10,32) and rame=0");
}
else
{
    $chk_rs = getdb("select MAX(createtime) from bet where lotto_id=" . $lotto_id . " and user_id=" . $curruser['id'] . " and bettype=" . $bettype . " and rame=0");
}
if (!$chk_rs->eof)
{
    $chktime2 = $chk_rs->f[0];
}
$chk_rs->close();
$chktime1 = systime();
if (intval($chktime1) - intval($chktime2) < 12)
{
    account_err("请於 " . ( 12 - ( intval($chktime1) - intval($chktime2) ) ) . "秒後才继续下注！");
}
$rs1 = getdb("select amount_6h from k_user_bet where user_id=" . $curruser['id'] . " and lotto_id=" . $lotto_id);
$usedamount = $rs1->f[0] ? $rs1->f[0] : 0;
$rs1->close();
$tpl->set("usedamount", $usedamount);
$maxMonTemp = 0;
$betforms = "";
$i = 0;
while ($i < count($num_r1))
{
    $num_r1[$i] = d2($num_r1[$i]);
    ++$i;
}
$num1 = implode(",", $num_r1);
$betforms .= "<input type=hidden name=\"num1\" value=\"" . $num1 . "\">\n";
if (!$normal)
{
    $i = 0;
    while ($i < count($num_r2))
    {
        $num_r2[$i] = d2($num_r2[$i]);
        ++$i;
    }
    $num2 = implode(",", $num_r2);
    $betforms .= "<input type=hidden name=\"num2\" value=\"" . $num2 . "\">\n";
}
$tpl->set("betforms", $betforms);
$tpl->set("type", $bettype);

$idisk = getUserValidDisk($curruser);
$disk = $g_disk_code[$idisk];
$tpl->set("diskStr", strtoupper($disk) . "盘");
if ($bettype == 8)
{
    $rs = getdb("select * from rate8 where lotto_id={$lotto_id} AND disk = " . $idisk . " LIMIT 1");
    if ($rs->eof)
    {
        account_err("系统目前维护中，请稍後！");
    }
    $rate8Arr = array();
    foreach ($num_r1 as $val)
    {
        $rate8Arr[$val] = floatval($rs->f["r" . d2($val)]);
    }
    foreach ($num_r2 as $val)
    {
        $rate8Arr[$val] = floatval($rs->f["r" . d2($val)]);
    }
    asort($rate8Arr);
    $idx = array_keys($rate8Arr);
    $rate1 = $rate8Arr[$idx[0]];
    $rate = $rate8Arr[$idx[count($rate8Arr) - 1]];
}
elseif ($bettype == 48)
{
    $rs = getdb("select * from rate9 where lotto_id={$lotto_id} AND disk = " . $idisk . " LIMIT 1");
    if ($rs->eof)
    {
        account_err("系统目前维护中，请稍後！");
    }
    $rate8Arr = array();
    foreach ($num_r1 as $val)
    {
        $rate8Arr[$val] = floatval($rs->f["r" . d2($val)]);
    }
    foreach ($num_r2 as $val)
    {
        $rate8Arr[$val] = floatval($rs->f["r" . d2($val)]);
    }
    asort($rate8Arr);
    $idx = array_keys($rate8Arr);
    $rate1 = $rate8Arr[$idx[0]];
    $rate = $rate8Arr[$idx[count($rate8Arr) - 1]];
}
else
{
    $rs = getdb("select * from rate5" . $disk . " where lotto_id={$lotto_id}");
    if ($rs->eof)
    {
        account_err("系统目前维护中，请稍後！");
    }
    $rate1 = $rs->f["r" . $bettype . "_1"];
    if (isset($rs->f["r" . $bettype . "_2"]))
    {
        $rate = $rate1 . "," . $rs->f["r" . $bettype . "_2"];
    }
    else
    {
        $rate = $rate1;
    }
}
$rs->close();

$old_rate1 = $rate1;
$old_rate2 = $rate;
$chk_rate1 = $rate1;
$chk_rate2 = $rate;
$checkarry = array();
$betcontent = "";
$chk_betnum = 0;
$err = 0;

if ($normal)
{
    $r1count = count($num_r1);
    $i = 0;
    while ($i < $r1count - 1)
    {
        if (intval($num_r1[$i]) < 1 || 49 < intval($num_r1[$i]))
        {
            ++$err;
            break;
        }
        $j = $i + 1;
        while ($j < $r1count)
        {
            if (intval($num_r1[$i]) == intval($num_r1[$j]) || ( intval($num_r1[$i]) < 1 || 49 < intval($num_r1[$i]) ))
            {
                ++$err;
                break;
            }
            $checkarry[0] = d2(intval($num_r1[$i]));
            $checkarry[1] = d2(intval($num_r1[$j]));
            sort($checkarry);
            $rpass = getline_number_rate($bettype, $checkarry, $disk);
            if ($rpass != false && $rpass[0] < $chk_rate1)
            {
                $chk_rate1 = $rpass[0];
                $chk_rate2 = $rpass[1];
            }
            ++$j;
        }
        ++$i;
    }
    if (0 < $err)
    {
        write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, "玩法(" . $bettype . ")，使用不正常方式下注（" . implode(",", $num_r1) . "）");
        account_err("请勿以不正常方式下注，你的 IP 已经被记录并已经通知你的上层管理了！");
    }
    else
    {
        $betcounts = GetCount($r1count, $count_num);
        $betUnionNum = $betcounts;
        $betcontent .= "[ " . $num1 . " ]<br>合计<font color=red><b id=nc>" . $betcounts . "</b></font>组，存成<font color=red><b>" . $betUnionNum . "</b></font>笔";
        if ($betUnionNum == 1)
        {
            $chk_betnum = 1;
        }
    }
}
else
{
    $betcounts = $betUnionNum;
    if (count($num_r1) < 3)
    {
        if (count($num_r1) == 2)
        {
            if (intval($num_r1[0]) == intval($num_r1[1]))
            {
                ++$err;
            }
            $checkarry[0] = d2(intval($num_r1[0]));
            $checkarry[1] = d2(intval($num_r1[1]));
            sort($checkarry);
            $rpass = getline_number_rate($bettype, $checkarry, $disk);
            if ($rpass != false)
            {
                if ($rpass[0] < $rate1)
                {
                    $chk_betnum = 1;
                }
                if ($rpass[0] < $chk_rate1)
                {
                    $chk_rate1 = $rpass[0];
                    $chk_rate2 = $rpass[1];
                }
            }
        }
        if ($err == 0)
        {
            $i = 0;
            while ($i < count($num_r1))
            {
                $j = 0;
                while ($j < count($num_r2))
                {
                    if (intval($num_r1[$i]) == intval($num_r2[$j]))
                    {
                        ++$err;
                    }
                    $checkarry[0] = d2(intval($num_r1[$i]));
                    $checkarry[1] = d2(intval($num_r2[$j]));
                    sort($checkarry);
                    $rpass = getline_number_rate($bettype, $checkarry, $disk);
                    if ($rpass != false && $rpass[0] < $chk_rate1)
                    {
                        $chk_rate1 = $rpass[0];
                        $chk_rate2 = $rpass[1];
                    }
                    ++$j;
                }
                ++$i;
            }
        }
        if (0 < $err)
        {
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, "玩法(" . $bettype . ")，使用不正常方式下注（胆 " . implode(",", $num_r1) . " 拖 " . implode(",", $num_r2) . "）");
            account_err("请勿以不正常方式下注，你的 IP 已经被记录并已经通知你的上层管理了！");
        }
        else
        {
            $betcontent .= "胆[ " . $num1 . " ] 拖 [ " . $num2 . " ]<br>合计<font color=red><b id=nc>" . $betUnionNum . "</b></font>组，存成<font color=red><b>" . $betUnionNum . "</b></font>笔";
            if ($betUnionNum == 1)
            {
                $chk_betnum = 1;
            }
        }
    }
    else
    {
        $r1count = count($num_r1);
        $i = 0;
        while ($i < $r1count - 1)
        {
            $j = $i + 1;
            while ($j < $r1count - 1)
            {
                if (intval($num_r1[$i]) == intval($num_r1[$j]))
                {
                    ++$err;
                }
                $checkarry[0] = d2(intval($num_r1[$i]));
                $checkarry[1] = d2(intval($num_r1[$j]));
                sort($checkarry);
                $rpass = getline_number_rate($bettype, $checkarry, $disk);
                if ($rpass != false && $rpass[0] < $chk_rate1)
                {
                    $chk_rate1 = $rpass[0];
                    $chk_rate2 = $rpass[1];
                }
                ++$j;
            }
            ++$i;
        }
        $r2count = count($num_r2);
        $i = 0;
        while ($i < $r2count - 1)
        {
            $nn2 = $num_r2[$i];
            $j = $i + 1;
            while ($j < $r2count)
            {
                if (intval($num_r2[$i]) == intval($num_r2[$j]))
                {
                    ++$err;
                }
                $checkarry[0] = d2(intval($num_r2[$i]));
                $checkarry[1] = d2(intval($num_r2[$j]));
                sort($checkarry);
                $rpass = getline_number_rate($bettype, $checkarry, $disk);
                if ($rpass != false && $rpass[0] < $chk_rate1)
                {
                    $chk_rate1 = $rpass[0];
                    $chk_rate2 = $rpass[1];
                }
                ++$j;
            }
            ++$i;
        }
        if (0 < $err)
        {
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, "玩法(" . $bettype . ")，使用不正常方式下注（" . implode(",", $num_r1) . " 碰 " . implode(",", $num_r2) . "）");
            account_err("请勿以不正常方式下注，你的 IP 已经被记录并已经通知你的上层管理了！");
        }
        else
        {
            $betcontent .= "[ " . $num1 . " ] 碰 [ " . $num2 . " ]<br>合计<font color=red><b id=nc>" . $betUnionNum . "</b></font>组，存成<font color=red><b>" . $betUnionNum . "</b></font>笔";
        }
    }
}
$ratechange = false;
$betcontents = "";
if ($chk_rate1 != $rate1)
{
    if (0 < $chk_betnum)
    {
        $betcontents = "<font color=red>" . $g_betname[$bettype] . "</font> @  <font color=red id=rate>" . $chk_rate2 . "</font><br>";
        $tpl->set("rates", $chk_rate2);
    }
    else
    {
        $betcontents = "<font color=red>" . $g_betname[$bettype] . "</font><br>";
        if ($rate1 < $chk_rate1)
        {
            $betcontents .= "最高赔率 @  <font color=red id=rate1>" . $chk_rate2 . "</font><br>";
            $betcontents .= "最低赔率 @  <font color=red id=rate>" . $rate . "</font><br>";
            $tpl->set("rates", $chk_rate2 . "～" . $rate);
        }
        else
        {
            $betcontents .= "最高赔率 @  <font color=red id=rate1>" . $rate . "</font><br>";
            $betcontents .= "最低赔率 @  <font color=red id=rate>" . $chk_rate2 . "</font><br>";
            $tpl->set("rates", $rate . "～" . $chk_rate2);
        }
    }
}
else if ($bettype == 8 || $bettype == 48 )
{
    $betcontents .= "最高赔率 @  <font color=red id=rate1>" . $rate . "</font><br>";
    $betcontents .= "最低赔率 @  <font color=red id=rate>" . $rate1 . "</font><br>";
}
else
{
    $betcontents = "<font color=red>" . $g_betname[$bettype] . "</font> @  <font color=red id=rate>" . $rate . "</font><br>";
    $tpl->set("rates", $rate);
}
$betcontents .= $betcontent;
$tpl->set("betcontent", $betcontents);
$tpl->set("betUnionNum", $betUnionNum);
$betmin = $conf->get("betmin");
$tpl->set("min", $betmin);
$betmax = $conf->get("betmax");
$tpl->set("max", $betmax);
$tpl->set("max_str", $betmax);
$betname = $g_betname[$bettype];
$tpl->set("betname", $betname);

if ($chk_rate1 + $chk_rate2 + 0 == 0)
{
    account_err($betname . "没有开放下注！");
}
$rs1 = getdb("select * from amounts where bettype=" . $bettype . " and user_id=" . $curruser['id']);
$amount1 = $rs1->f['amount1'] - 0;
$amount2 = $rs1->f['amount2'] - 0;
if ($amount1 == 0 || $amount2 == 0)
{
    account_err($betname . "没有开放下注！");
}
$rs1 = getdb("select sum(amount) as amount,numbers,line_nums from bet where bettype=" . $bettype . " and user_id=" . $curruser['id'] . " and lotto_id=" . $lotto_id . " and rame=0 group by numbers");
                                while (!$rs1->eof)
                                {
                                   if ($rs1->f['line_nums'] == $num1)
                                    {
                                        $bet += $rs1->f['amount'];//已下注每期总额
                                    }
                                    
                                    $rs1->movenext();
                                }
	$m = $amount2-$bet;
$tpl->set("amount1", $amount1);
$tpl->set("amount2", $amount2);
$tpl->set("amount1_str", $amount1);
$tpl->set("amount2_str", $m);
$usemaxamount = $curruser['usemaxamount'];
if (isset($_POST['money']) && $ratechange == false)
{
    $money = intval($_POST['money']);
    if ($money == 0 || $betcounts <= 0)
    {
        write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, "使用外挂攻击");
        account_err("不要随便攻击本站，你的 IP 已经被记录了！");
    }
	
    $betmoney = $money * $betcounts;
    if ($money < $betmin)
    {
        account_err("下注金额小於最低限额！");
    }
    if ($amount1 < $money)
    {
        account_err("下注金额超过单注限额！");
    }
    if ($curruser['balance'] < $betmoney)
    {
        account_err("下注总金额超过信用额度！");
    }
    if ($m < $betmoney)
    {
        account_err("下注金总额超过本期限额！");
    }
    if ($conf->get("linebet") <= date("Hi"))
    {
        account_err("已经截止下注！");
    }
    $stime = systime();

    if ($normal)
    {
        $len = count($num_r1);
        if ($count_num == 3)
        {
            $i = 0;
            while ($i <= $len - 2)
            {
                $j = $i + 1;
                while ($j <= $len - 2)
                {
                    $k = $j + 1;
                    while ($k < $len)
                    {
                        $rate1 = $old_rate1;
                        $rate = $old_rate2;
                        $nums = explode(",", $num_r1[$i] . "," . $num_r1[$j] . "," . $num_r1[$k]);
                        sort($nums);
                        reset($nums);

                        if (count($nums) != $count_num)
                        {
                            err("注单存取错误！");
                        }
                        if ($bettype == 8)
                        {
                            $rate1 = min($rate8Arr[$nums[0]], $rate8Arr[$nums[1]]);
                            $rate1 = min($rate1, $rate8Arr[$nums[2]]);
                            $rate = $rate1;
                        }
                        if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
                        {
                            account_err("号码:" . implode(",", $num) . "超过额度！");
                        }
                        ++$k;
                    }
                    ++$j;
                }
                ++$i;
            }
        }
		else if ($count_num == 4)
        {
            $i = 0;
            while ($i <= $len - 3)
            {
                $j = $i + 1;
                while ($j <= $len - 2)
                {
                    $k = $j + 1;
                    while ($k < $len-1)
                    {
                        $l = $k + 1;
						while ($l < $len)
						{
							$rate1 = $old_rate1;
							$rate = $old_rate2;
							$nums = explode(",", $num_r1[$i] . "," . $num_r1[$j] . "," . $num_r1[$k]. "," . $num_r1[$l]);
							sort($nums);
							reset($nums);
							if (count($nums) != $count_num)
							{
								err("注单存取错误！");
							}
							if ($bettype == 48)
							{
								$rate1 = min($rate8Arr[$nums[0]], $rate8Arr[$nums[1]]);
								$rate1 = min($rate1, $rate8Arr[$nums[2]]);
								$rate = $rate1;
							}
							if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
							{
								account_err("号码:" . implode(",", $num) . "超过额度！");
							}
							++$l;
						}
                        ++$k;
                    }
                    ++$j;
                }
                ++$i;
            }
        }
        else
        {
            if ($count_num == 2)
            {
                $i = 0;
                while ($i <= $len - 2)
                {
                    $j = $i + 1;
                    while ($j < $len)
                    {
                        $rate1 = $old_rate1;
                        $rate = $old_rate2;
                        $nums = explode(",", $num_r1[$i] . "," . $num_r1[$j]);
                        sort($nums);
                        reset($nums);
                        if (count($nums) != $count_num)
                        {
                            err("注单存取错误！");
                        }
                        $rpass = getline_number_rate($bettype, $nums, $disk);
                        if ($rpass != false)
                        {
                            $rate1 = $rpass[0];
                            $rate = $rpass[1];
                        }
                        if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
                        {
                            account_err("号码:" . implode(",", $num) . "超过额度！");
                        }
                        ++$j;
                    }
                    ++$i;
                }
            }
        }
    }
    else if (count($num_r1) < 3)
    {
        $i = 0;
		if($count_num<=3){
			while ($i < count($num_r2))
			{
				$rate1 = $old_rate1;
				$rate = $old_rate2;
				$nums = explode(",", $num1 . "," . $num_r2[$i]);
				sort($nums);
				reset($nums);
				if (count($nums) != $count_num)
				{
					err("注单存取错误！");
				}
				if ($count_num == 2)
				{
					$rpass = getline_number_rate($bettype, $nums, $disk);
					if ($rpass != false)
					{
						$rate1 = $rpass[0];
						$rate = $rpass[1];
					}
				}
				else if ($bettype == 8)
				{
					$rate1 = min($rate8Arr[$nums[0]], $rate8Arr[$nums[1]]);
					$rate1 = min($rate1, $rate8Arr[$nums[2]]);
					$rate = $rate1;
				}
				if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
				{
					account_err("号码:" . implode(",", $num) . "超过额度！");
				}
				++$i;
			}
		}
		else{
			$len=count($num_r2);
			while ($i < $len)
			{
				$j = $i + 1;
				while ($j < $len) 
				{
					$rate1 = $old_rate1;
					$rate = $old_rate2;
					$nums = explode(",", $num1 . "," . $num_r2[$i] . "," . $num_r2[$j]);
					sort($nums);
					reset($nums);
					if (count($nums) != $count_num)
					{
						err("注单存取错误！");
					}
					if ($count_num == 2)
					{
						$rpass = getline_number_rate($bettype, $nums, $disk);
						if ($rpass != false)
						{
							$rate1 = $rpass[0];
							$rate = $rpass[1];
						}
					}
					else if ($bettype == 8)
					{
						$rate1 = min($rate8Arr[$nums[0]], $rate8Arr[$nums[1]]);
						$rate1 = min($rate1, $rate8Arr[$nums[2]]);
						$rate = $rate1;
					}
					if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
					{
						account_err("号码:" . implode(",", $num) . "超过额度！");
					}
					$j++;
				}
				++$i;
			}	
		}
    }
    else
    {
        $i = 0;
        while ($i < count($num_r1))
        {
            $cn1 = $num_r1[$i];
            $j = 0;
            while ($j < count($num_r2))
            {
                $cn2 = $num_r2[$j];
                if ($cn1 != $cn2)
                {
                    $rate1 = $old_rate1;
                    $rate = $old_rate2;
                    $nums = explode(",", $cn1 . "," . $cn2);
                    sort($nums);
                    reset($nums);
                    if (count($nums) != $count_num)
                    {
                        err("注单存取错误！");
                    }
                    $rpass = getline_number_rate($bettype, $nums, $disk);
                    if ($rpass != false)
                    {
                        $rate1 = $rpass[0];
                        $rate = $rpass[1];
                    }
                    if (!betin($bettype, $nums, $rate1, $rate, $money, 1, $prot_start, $stime, $amount2, $idisk))
                    {
                        account_err("号码:" . implode(",", $num) . "超过额度！");
                    }
                }
                ++$j;
            }
            ++$i;
        }
    }
    $payoff = round($money * ( $rate1 - 1 ));
    $tpl->load("succ", "succ.htm");
    $tpl->set("ordertype", $betcontent);
    $tpl->set("money", $betmoney);
    $tpl->set("payoff", $payoff);
    $tpl->set("myscript", "parent.mainFrame.location.reload();");
    $tpl->show("succ");
}
else
{
    if ($ratechange == true)
    {
        if (isset($_POST['money']))
        {
            $money = intval($_POST['money']);
            $tpl->set("money", $money);
        }
        $tpl->set("message", "<tr><td colspan=2 bgcolor=red align=center><font color=white>赔率已经变动！</font></td></tr>");
    }
    $tpl->show("main");
}
?>